package com.jt.yygh.common.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import javafx.scene.control.RadioMenuItem;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author jiang tao
 * @date 2022/2/17
 * @description:
 **/
@Data
@ApiModel(value = "全局统一返回分页结果")
public class ResultPage <T>{

    @ApiModelProperty(value = "返回码")
    private Integer code;

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "返回数据")
    private List<T> data;

    @ApiModelProperty(value = "第几页")
    private int pageNum;

    @ApiModelProperty(value = "每页数据量的大小")
    private int pageSize;

    @ApiModelProperty(value = "总页数")
    private long totalPages;

    @ApiModelProperty(value = "结果总数")
    private long totalCount;

    public ResultPage(){
        this.pageNum = 0;
        this.pageSize = 0;
        this.totalPages = 0L;
        this.totalCount = 0L;
    }

    public ResultPage(Integer code, String message){
        this(code, message,(List) null);
    }

    public ResultPage(Integer code, String message, List<T> data){
        this.code = code;
        this.message = message;
        this.data = data;
        this.pageNum = 0;
        this.pageSize = 0;
        this.totalPages = 0L;
        this.totalCount = 0L;
    }

    public static <T extends Serializable> ResultPage<T> success(List<T> data){
        ResultPage resultPage = new ResultPage();
        resultPage.setCode(ResultCodeEnum.SUCCESS.getCode());
        resultPage.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        resultPage.setData(data);
        return resultPage;
    }

    public static <T extends Serializable> ResultPage<T> success(int pageNum, int pageSize, long totalCount, List<T> data){
        ResultPage resultPage = new ResultPage();
        resultPage.setCode(ResultCodeEnum.SUCCESS.getCode());
        resultPage.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        resultPage.setData(data);

        resultPage.setPageNum(pageNum);
        resultPage.setPageSize(pageSize);
        resultPage.setTotalCount(totalCount);
        return resultPage;
    }
    public static <T extends Serializable> ResultPage<T> fail(Integer code, String message){
        ResultPage resultPage = new ResultPage();
        resultPage.setCode(code);
        resultPage.setMessage(message);
        return resultPage;
    }

    public static <T extends Serializable> ResultPage<T> fail(ResultCodeEnum resultCodeEnum){
        ResultPage resultPage = new ResultPage();
        resultPage.setCode(resultPage.getCode());
        resultPage.setMessage(resultPage.getMessage());
        return resultPage;
    }








}
